Skip to content

fix(security): restrict /monitoring/events to configured administrators (Closes #101) - #163

Merged
harsharajkumar-273 merged 1 commit into
harsharajkumar-273:mainfrom
SakethSumanBathini:fix/101-monitoring-events-admin-only
Jul 29, 2026
Merged

fix(security): restrict /monitoring/events to configured administrators (Closes #101)#163
harsharajkumar-273 merged 1 commit into
harsharajkumar-273:mainfrom
SakethSumanBathini:fix/101-monitoring-events-admin-only

Conversation

@SakethSumanBathini

@SakethSumanBathini SakethSumanBathini commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Closes #101

Problem

GET /monitoring/events in backend/src/routes/system.routes.ts is mounted with requireAccessToken and nothing else. That middleware only proves someone is authenticated — it performs no role or ownership check.

The endpoint returns readRecentMonitoringEvents(), which is the system-wide event log: backend and frontend stack traces, internal filesystem paths, request metadata and user agents for every user of the instance. Any authenticated caller — a regular contributor, a guest session, or anyone holding a bearer token — can read all of it.

Change

backend/src/middleware/auth.ts — adds a requireAdmin middleware backed by a new PROOFDESK_ADMIN_LOGINS variable (comma-separated GitHub logins, matching the existing PROOFDESK_* convention).

It denies in three cases, all deliberately fail-closed:

  • the allow-list is empty or unset. An unconfigured allow-list means "no administrators have been designated", never "everyone qualifies";
  • there is no authenticated session. requireAccessToken also accepts a raw bearer token, and in that path req.authSession is null — a bearer token on its own carries no verified identity to compare against the list;
  • the session login is not on the list.

Logins are compared case-insensitively, matching GitHub's own treatment. The list is parsed per request so an operator can change it without a rebuild.

Identity is read from req.authSession?.user?.login — the same primitive the existing checkWorkspaceOwner middleware already uses, rather than introducing a second notion of identity.

backend/src/routes/system.routes.ts/monitoring/events now runs requireAccessToken, requireAdmin.

.env.example — documents the new variable.

Compatibility

Nothing in the repository reads /monitoring/events — the only occurrence of that path anywhere is the route definition itself. The frontend posts to /monitoring/client-error but never reads the event log back. So restricting it removes no existing functionality; an operator who wants access adds their login to PROOFDESK_ADMIN_LOGINS.

Verification

  • npx tsc --noEmit in backend/ clean.
  • requireAdmin exercised across all seven paths: unset allow-list denies, non-admin denies, admin passes, case-mismatched login passes, bearer-token-without-session denies, session-without-login denies, whitespace-padded multi-entry list passes.

Observation, not addressed here

GET /metrics (line 42 of the same file) has the same shape — requireAccessToken with no role check — and exposes the Prometheus register. I've left it alone since #101 names only /monitoring/events, but if you'd like it under the same guard, say so and I'll add it here or open it separately.

Note: npm test is red on clean main independently of this branch.

Summary by CodeRabbit

  • Security
    • Restricted access to monitoring events to approved administrators.
    • Requests without an approved administrator login now receive a 403 response.
    • Added configuration documentation for specifying administrator GitHub logins.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0b3e3a17-7c96-4d3d-a0c8-cd0988ecd07f

📥 Commits

Reviewing files that changed from the base of the PR and between 2f06e6e and 9258440.

📒 Files selected for processing (3)
  • .env.example
  • backend/src/middleware/auth.ts
  • backend/src/routes/system.routes.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: test
🧰 Additional context used
🪛 dotenv-linter (4.0.0)
.env.example

[warning] 54-54: [UnorderedKey] The PROOFDESK_ADMIN_LOGINS key should go before the PROOFDESK_DATA_DIR key

(UnorderedKey)

🔇 Additional comments (4)
.env.example (1)

52-54: LGTM!

backend/src/middleware/auth.ts (2)

39-52: LGTM!


71-78: 🎯 Functional Correctness

No auth-session gap here. requireAccessToken populates req.authSession via extractAccessToken, and /monitoring/events is mounted as requireAccessToken, requireAdmin, so allowlisted sessions reach requireAdmin; bearer-token-only requests intentionally fail closed with 403.

			> Likely an incorrect or invalid review comment.
backend/src/routes/system.routes.ts (1)

2-2: LGTM!

Also applies to: 79-82


📝 Walkthrough

Walkthrough

Adds a configurable GitHub-login administrator allowlist and applies it to GET /monitoring/events, returning HTTP 403 for unconfigured, unauthenticated, or unauthorized requests.

Changes

Monitoring event authorization

Layer / File(s) Summary
Administrator allowlist middleware
.env.example, backend/src/middleware/auth.ts
Documents PROOFDESK_ADMIN_LOGINS, parses configured logins case-insensitively, and adds requireAdmin responses for unauthorized access.
Monitoring route protection
backend/src/routes/system.routes.ts
Requires both requireAccessToken and requireAdmin for GET /monitoring/events.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant requireAccessToken
  participant requireAdmin
  participant MonitoringEvents
  Client->>requireAccessToken: Request GET /monitoring/events
  requireAccessToken->>requireAdmin: Authenticated request with authSession
  requireAdmin->>MonitoringEvents: Allow configured administrator login
  MonitoringEvents-->>Client: Monitoring events response
Loading

Suggested reviewers: harsharajkumar-273

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: restricting /monitoring/events to configured administrators.
Linked Issues check ✅ Passed The PR enforces admin-only access on /monitoring/events, matching issue #101's requirement to fix broken function-level authorization.
Out of Scope Changes check ✅ Passed The changes are focused on the authorization fix and environment documentation, with no unrelated scope detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@harsharajkumar-273 harsharajkumar-273 added ELUSOC Required Tracking ADVENTURER Intermediate (25 pts) labels Jul 29, 2026
@harsharajkumar-273
harsharajkumar-273 merged commit ef4783d into harsharajkumar-273:main Jul 29, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ADVENTURER Intermediate (25 pts) ELUSOC Required Tracking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Broken Function Level Authorization (BFLA) on System Monitoring Events

2 participants